package cn.zjitc.exam.service.impl;

import cn.zjitc.exam.domain.Product;
import cn.zjitc.exam.mapper.ProductMapper;
import cn.zjitc.exam.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    private final ProductMapper productMapper;

    public ProductServiceImpl(ProductMapper productMapper) {
        this.productMapper = productMapper;
    }

    @Override
    public void save(Product product) {
        productMapper.save(product);
    }

    @Override
    public void delete(Integer id) {
        productMapper.delete(id);

    }

    @Override
    public void update(Product product) {
        productMapper.update(product);
    }



    @Override
    public List<Product> findAll() {
        return productMapper.findAll();
    }

    @Override
    public List<Product> findByPage(int page, int size) {
        int offset = (page - 1) * size;
        return productMapper.findByPage(offset, size);
    }

    @Override
    public List<Product> search(String keyword, int page, int size) {
        int offset = (page - 1) * size;
        return productMapper.search(keyword, offset, size);
    }

    @Override
    public int count() {
        return productMapper.count();
    }

    @Override
    public int countByKeyword(String keyword) {
        return productMapper.countByKeyword(keyword);
    }

    @Override
    public Product findById(Integer id) {
        return productMapper.findById(id);
    }
}
